﻿namespace FrameWork.Request;

public class RequestResponseModel
{
    /// <summary>
    ///     状态码
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    ///     信息
    /// </summary>
    public string Message { get; set; }

    /// <summary>
    ///     数据
    /// </summary>
    public object? Data { get; set; }
}

public class RequestResponse
{
    /**
     * 创建返回
     */
    public static RequestResponseModel CreateResponse(int Status, string Message, object? Data = null)
    {
        return new RequestResponseModel
        {
            Status = Status,
            Message = Message,
            Data = Data
        };
    }

    /**
     * 200 - 成功调用
     */
    public static RequestResponseModel OK(object? Data, string? Message = "调用成功")
    {
        return CreateResponse(200, Message, Data);
    }

    /**
     * 400 - 用户传入参数错误
     */
    public static RequestResponseModel BadRequest(string Message, object? Data = null)
    {
        return CreateResponse(400, Message, Data);
    }

    /**
     * 401 - 登录凭证过期
     */
    public static RequestResponseModel Unauthorized(string Message, object? Data = null)
    {
        return CreateResponse(401, Message, Data);
    }

    /**
     * 403 - 用户无权访问资源
     */
    public static RequestResponseModel Forbidden(string Message, object? Data = null)
    {
        return CreateResponse(403, Message, Data);
    }

    /**
     * 404 - URL路径错误、资源已被删除
     */
    public static RequestResponseModel NotFound(string Message, object? Data = null)
    {
        return CreateResponse(404, Message, Data);
    }

    /**
     * 422 - 开发人员传入参数错误
     */
    public static RequestResponseModel ErrorRequest(string Message, object? Data = null)
    {
        return CreateResponse(422, Message, Data);
    }

    /**
     * 500 - 服务器错误
     */
    public static RequestResponseModel ServerError(object? Data = null)
    {
        return CreateResponse(500, "未知错误，请联系管理员！", Data);
    }
}